package com.landinfo.service.impl;

import com.landinfo.service.PatrolRecordService;
import com.landinfo.domain.PatrolRecord;
import com.landinfo.repository.PatrolRecordRepository;
import com.landinfo.service.dto.PatrolRecordDTO;
import com.landinfo.service.mapper.PatrolRecordMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * Service Implementation for managing PatrolRecord.
 */
@Service
@Transactional
public class PatrolRecordServiceImpl implements PatrolRecordService{

    private final Logger log = LoggerFactory.getLogger(PatrolRecordServiceImpl.class);

    private final PatrolRecordRepository patrolRecordRepository;

    private final PatrolRecordMapper patrolRecordMapper;

    public PatrolRecordServiceImpl(PatrolRecordRepository patrolRecordRepository, PatrolRecordMapper patrolRecordMapper) {
        this.patrolRecordRepository = patrolRecordRepository;
        this.patrolRecordMapper = patrolRecordMapper;
    }

    /**
     * Save a patrolRecord.
     *
     * @param patrolRecordDTO the entity to save
     * @return the persisted entity
     */
    @Override
    public PatrolRecordDTO save(PatrolRecordDTO patrolRecordDTO) {
        log.debug("Request to save PatrolRecord : {}", patrolRecordDTO);
        PatrolRecord patrolRecord = patrolRecordMapper.toEntity(patrolRecordDTO);
        patrolRecord = patrolRecordRepository.save(patrolRecord);
        return patrolRecordMapper.toDto(patrolRecord);
    }

    /**
     *  Get all the patrolRecords.
     *
     *  @param pageable the pagination information
     *  @return the list of entities
     */
    @Override
    @Transactional(readOnly = true)
    public Page<PatrolRecordDTO> findAll(Pageable pageable) {
        log.debug("Request to get all PatrolRecords");
        return patrolRecordRepository.findAll(pageable)
            .map(patrolRecordMapper::toDto);
    }

    /**
     *  Get one patrolRecord by id.
     *
     *  @param id the id of the entity
     *  @return the entity
     */
    @Override
    @Transactional(readOnly = true)
    public PatrolRecordDTO findOne(Long id) {
        log.debug("Request to get PatrolRecord : {}", id);
        PatrolRecord patrolRecord = patrolRecordRepository.findById(id).get();
        return patrolRecordMapper.toDto(patrolRecord);
    }

    /**
     *  Delete the  patrolRecord by id.
     *
     *  @param id the id of the entity
     */
    @Override
    public void delete(Long id) {
        log.debug("Request to delete PatrolRecord : {}", id);
        patrolRecordRepository.deleteById(id);
    }
}
